import mockApi from "@/api/mockApi";
import type {RecruiterForm} from '@/types/req/recruiterForm'
import type {RecruiterQueryForm} from '@/types/req/recruiterQueryForm'
import type {Recruiter} from '@/types/resp/recruiter'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";

export default class recruiterApi {
  static recruiters: Recruiter[] = [
    {"id":1,"enterpriseId":4,"enterpriseName":"江洋科技","username":"zhangwei","name":"张伟","password":"zhangwei123","contactPhone":"13800138000","email":"zhangwei@tencent.com","createTime":"2024-12-26 22:43:13","modifyTime":"2024-07-11 22:43:13"},
    {"id":2,"enterpriseId":4,"enterpriseName":"腾王科技","username":"liumei","name":"刘梅","password":"liumei456","contactPhone":"13800138001","email":"liumei@tencent.com","createTime":"2024-09-14 22:43:13","modifyTime":"2024-09-05 22:43:13"},
    {"id":3,"enterpriseId":4,"enterpriseName":"快讯科技","username":"wangli","name":"王丽","password":"wangli789","contactPhone":"13800138002","email":"wangli@tencent.com","createTime":"2024-03-07 22:43:13","modifyTime":"2024-04-28 22:43:13"},
    {"id":4,"enterpriseId":4,"enterpriseName":"腾讯科技","username":"chengang","name":"陈刚","password":"chengang101","contactPhone":"13800138003","email":"chengang@tencent.com","createTime":"2024-10-21 22:43:13","modifyTime":"2024-06-14 22:43:13"},
    {"id":5,"enterpriseId":3,"enterpriseName":"阿里巴巴","username":"lixia","name":"李霞","password":"lixia202","contactPhone":"13800138004","email":"lixia@alibaba.com","createTime":"2024-11-02 22:43:13","modifyTime":"2024-08-05 22:43:13"}
  ];

  static async save (recruiterForm: RecruiterForm): Promise<Result<void>> {
    console.log('recruiterApi save params', recruiterForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (recruiterQueryForm: RecruiterQueryForm): Promise<Result<Page<Recruiter>>> {
    console.log('recruiterApi find params', recruiterQueryForm)
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(recruiterApi.recruiters)
    return response.data
  }

  static async findById (id: number): Promise<Result<Recruiter>> {
    console.log('recruiterApi findById id', id)
    let target = {}
    for (const a of recruiterApi.recruiters) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<Recruiter> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('recruiterApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}
